package logic

import (
	"context"
	"king/model/mysql"

	"king/kingrpc/internal/svc"
	"king/kingrpc/kingrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type ProductShowLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewProductShowLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ProductShowLogic {
	return &ProductShowLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *ProductShowLogic) ProductShow(in *kingrpc.ProductShowRequest) (*kingrpc.ProductShowResponse, error) {
	// todo: add your logic here and delete this line

	var product mysql.Product
	mysql.DB.Debug().Where("id=?", in.Id).First(&product)

	return &kingrpc.ProductShowResponse{
		Title: product.Title,
		Price: float32(product.Price),
		Stock: product.Stock,
		Sales: product.Sales,
		Image: product.Image,
	}, nil
}
